package com.hwh.bootdemoweb.Netty第六章;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class TestJdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1.创建一个固定大小的线程池
        ExecutorService service = Executors.newFixedThreadPool(2);

        //2.提交任务
        Future<Object> future = service.submit(() -> {
            log.debug("执行计算....");
            Thread.sleep(1000);
            return 50;
        });

        //3.主线程通过future来获取结果
        log.debug("等待结果。。。。");
        future.get();
        log.debug("获取结果{}",future.get());
    }
}
